#!/usr/bin/runhugs
-- Calculates basic LCD monitor parameters from diagonals.
--
-- Copyright (c) bkil, 2009
-- License: GNU GPL v2 (or later), see the
--  attached gpl-2.0.txt for details.
--
--Changelog:
-- 2009.01.20 v0.0 first release
-- 2009.01.22 v0.1 refactoring: cleanup, typo in comments
-- 2009.01.29 v0.2 refactoring: friendlier names, Html type
-- 2009.01.30 v0.2.1 messy version
-- 2013.08.29 v0.2.2 DPI, HD added
--

--the routine that calculates all the parameters
-- input: diagonal, horizontal pixels, vertical pixels
--
getparams :: Float -> Int -> Int -> String
getparams diag_inch xi yi =
 show diag_inch ++ "in; " ++
 show a ++ ":" ++ show b ++ "; " ++
 show xi ++ "px; " ++
 show yi ++ "px; " ++
 show dpi ++ "dpi; " ++
 show dotpitch ++ "mm; " ++
 show megapix ++ "megapx; " ++
 show area_cm ++ "cm^2; " ++
 show w ++ "mm; " ++
 show h ++ "mm"
  where
  a = xi `div` (gcd xi yi)
  b = yi `div` (gcd xi yi)
  x = fromIntegral xi ;  y = fromIntegral yi
  diag = diag_inch * inch_mm
  inch_mm = 25.4  -- 1 inch in millimeters
  aspect = x/y
  calcdiag = sqrt (aspect*aspect + 1*1)
  scale = diag/calcdiag
  w = scale*aspect ;  h = scale*1
  area_cm = w*h / 1e2
  megapix = x*y / 1e6
  dotpitch = w/x
  dpi = x / (w/inch_mm)

--outputs a few parameters of common computer displays
main = putStr result  where
 result = unlines results
 results = [getparams diag x y | (diag,x,y) <- modes ]
 modes = [
  (13,640,480),
  (13,800,600),
  (15,1024,768),
  (17,1280,1024),
  (19,1440,900),
  (19,1280,1024),
  (20,1680,1050),
  (20,1600,1200),
  (22,1680,1050),
  (23.6,1920,1080)
  ]
